<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Extract the contents of a tar/zip archive to a directory</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="phardata.destruct.html">« PharData::__destruct</a></li>
      <li style="float: right;"><a href="phardata.iswritable.html">PharData::isWritable »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.phardata.html">PharData</a></li>
    <li>Extract the contents of a tar/zip archive to a directory</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="phardata.extractto" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">PharData::extractTo</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.3.0, PHP 7, PHP 8, PECL phar &gt;= 2.0.0)</p><p class="refpurpose"><span class="refname">PharData::extractTo</span> &mdash; <span class="dc-title">Extract the contents of a tar/zip archive to a directory</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-phardata.extractto-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><strong>PharData::extractTo</strong></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$directory</code></span>, <span class="methodparam"><span class="type"><span class="type">array</span>|<span class="type">string</span>|<span class="type">null</span></span> <code class="parameter">$files</code><span class="initializer"> = <strong><code>null</code></strong></span></span>, <span class="methodparam"><span class="type">bool</span> <code class="parameter">$overwrite</code><span class="initializer"> = <strong><code>false</code></strong></span></span>): <span class="type">bool</span></div>


  <p class="para rdfs-comment">
   Extract all files within a tar/zip archive to disk.  Extracted files and directories preserve
   permissions as stored in the archive.  The optional parameters allow optional control over
   which files are extracted, and whether existing files on disk can be overwritten.
   The second parameter <code class="literal">files</code> can be either the name of a file or
   directory to extract, or an array of names of files and directories to extract.  By
   default, this method will not overwrite existing files, the third parameter can be
   set to true to enable overwriting of files.
   This method is similar to <span class="function"><a href="ziparchive.extractto.html" class="function">ZipArchive::extractTo()</a></span>.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-phardata.extractto-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">directory</code></dt>

     <dd>

      <p class="para">
       Path to extract the given <code class="literal">files</code> to
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">files</code></dt>

     <dd>

      <p class="para">
       The name of a file or directory to extract, or an array of files/directories to extract
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">overwrite</code></dt>

     <dd>

      <p class="para">
       Set to <strong><code>true</code></strong> to enable overwriting existing files
      </p>
     </dd>

    
   </dl>

  </p>

 </div>

 <div class="refsect1 returnvalues" id="refsect1-phardata.extractto-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   returns <strong><code>true</code></strong> on success, but it is better to check for thrown exception,
   and assume success if none is thrown.
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-phardata.extractto-errors">
  <h3 class="title">错误／异常</h3>
  <p class="para">
   Throws <span class="classname"><a href="class.pharexception.html" class="classname">PharException</a></span> if errors occur while flushing
   changes to disk.
  </p>
 </div>



 <div class="refsect1 examples" id="refsect1-phardata.extractto-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-776">
    <p><strong>示例 #1 A <span class="function"><strong>PharData::extractTo()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">try&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$phar&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">PharData</span><span style="color: #007700">(</span><span style="color: #DD0000">'myphar.tar'</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$phar</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">extractTo</span><span style="color: #007700">(</span><span style="color: #DD0000">'/full/path'</span><span style="color: #007700">);&nbsp;</span><span style="color: #FF8000">//&nbsp;extract&nbsp;all&nbsp;files<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$phar</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">extractTo</span><span style="color: #007700">(</span><span style="color: #DD0000">'/another/path'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'file.txt'</span><span style="color: #007700">);&nbsp;</span><span style="color: #FF8000">//&nbsp;extract&nbsp;only&nbsp;file.txt<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$phar</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">extractTo</span><span style="color: #007700">(</span><span style="color: #DD0000">'/this/path'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;array(</span><span style="color: #DD0000">'file1.txt'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'file2.txt'</span><span style="color: #007700">));&nbsp;</span><span style="color: #FF8000">//&nbsp;extract&nbsp;2&nbsp;files&nbsp;only<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$phar</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">extractTo</span><span style="color: #007700">(</span><span style="color: #DD0000">'/third/path'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">null</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">);&nbsp;</span><span style="color: #FF8000">//&nbsp;extract&nbsp;all&nbsp;files,&nbsp;and&nbsp;overwrite<br /></span><span style="color: #007700">}&nbsp;catch&nbsp;(</span><span style="color: #0000BB">Exception&nbsp;$e</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;handle&nbsp;errors<br /></span><span style="color: #007700">}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-phardata.extractto-notes">
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">注意</strong>: <p class="para">Windows NTFS file systems
do not support some characters in filenames, namely <code class="literal">&lt;|&gt;*?&quot;:</code>. Filenames with a trailing dot
are not supported either. Contrary to some extraction tools, this method does not replace these characters with
an underscore, but instead fails to extract such files.</p></p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-phardata.extractto-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="phar.extractto.html" class="function" rel="rdfs-seeAlso">Phar::extractTo()</a> - Extract the contents of a phar archive to a directory</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>